package cook.controllers;

import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

import java.io.IOException;

import org.apache.solr.client.solrj.SolrServerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cook.services.SolrService;

@RestController
@RequestMapping("/control/")
public class SolrController {

    @Autowired
    private SolrService solrService;

    @RequestMapping(value = "/reindex", method = { POST, GET })
    public String reindex() throws SolrServerException, IOException {
        solrService.reindex();
        return "OK";
    }

    @RequestMapping(value = "/delete", method = { POST, GET })
    public String delete() throws SolrServerException, IOException {
        solrService.deleteAll();
        return "OK";
    }
}
